package com.more.spring.boot.mapper;

import com.more.spring.boot.pojo.User;
import com.more.spring.boot.provider.UserSqlBuilder;
import org.apache.ibatis.annotations.*;

import java.util.List;


/**
 * @CacheNamespace开启二级缓存
 */
@CacheNamespace
public interface UserByAnnotationMapper {

    @Insert("insert into user_tb(uname, gender) values(#{uname}, #{gender})")
    @Options(useGeneratedKeys = true, keyProperty = "id")
    public int insertAotoIncreUser3(User uer);

    @Insert("insert into user_tb(uname, gender) values(#{uname}, #{gender})")
    @Options(useGeneratedKeys = true, keyProperty = "id")
    int insertAotoIncreUser(User user);

    @Insert("insert into user_tb(uname, gender) values(#{uname}, #{gender})")
    @Options(useGeneratedKeys = true, keyProperty = "id")
    int insertAotoIncreUser2(String uname, String gender);


    @Select("select id, uname, gender from user_tb where id = #{id}")
    User selectAnnotationUserById(int id);

    @Results(id ="userResult", value = {
            @Result(property = "id", column ="id", id = true),
            @Result(property = "uname", column = "uname"),
            @Result(property = "gender", column = "gender")
    })
    @Select("select id, uname, gender from user_tb")
    List<User> selectAnnotationResultUser();


    @Results(id = "constructResultMap")
    @ConstructorArgs({
            @Arg(column = "id", javaType = int.class, id =true),
            @Arg(column = "uname", javaType = String.class),
            @Arg(column = "gender", javaType = String.class)
    })
    @Select("select id, uname, gender from user_tb")
    List<User> selectAnnotationConstrctUser();


    @SelectProvider(type = UserSqlBuilder.class, method="getUsersByName")
    List<User> getUserByName(String uname);
}
